﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcCms.Service.Models
{
    // ModelBinder to take parameters sent from DataTables
    public class MvcCmsMobileGridModelBinding : IModelBinder
    {
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var newRequest = new MvcCmsMobileGridRequest();
            var httpRequest = controllerContext.HttpContext.Request.Params;

            newRequest.PageNumber = int.Parse(httpRequest["PageNumber"]);
            newRequest.ResultsPerPage = int.Parse(httpRequest["ResultsPerPage"]);
            newRequest.ColumnToSearch = httpRequest["ColumnToSearch"].TryTrim();
            newRequest.ColumnToSortBy = httpRequest["ColumnToSortBy"].TryTrim();
            newRequest.SortOrder = httpRequest["SortOrder"].TryTrim();
            newRequest.Query = httpRequest["Query"];

            return newRequest;
        }
    }
}